package com.dongss.study.controller;

import com.dongss.study.common.utils.ResultVo;
import com.dongss.study.vo.request.UserRequestVo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by dongshuanshuan on 17-7-29.
 */
@Controller
public class LoginController {

    @RequestMapping("public/loginValidate")
    @ResponseBody
    public ResultVo loginValidate(@RequestBody UserRequestVo vo){

        System.out.println("username:"+vo.getUsername());

        System.out.println("password:"+vo.getPassword());

        UsernamePasswordToken token=new UsernamePasswordToken(vo.getUsername(),vo.getPassword());

        try{
            SecurityUtils.getSubject().login(token);
            //没有异常，则登录成功
            return new ResultVo("0","登陆成功",null);
        }catch(Exception e){
            e.printStackTrace();
            return new ResultVo("-1","用户名或密码错误",null);
        }
    }
//
//    @RequestMapping("logout")
//    public void logout(){
//        SecurityUtils.getSubject().logout();
//    }
}
